/**
 * @file:          EncoderCalibrator.h
 * @brief:         
 * @details:       
 * @author:        wjh
 * @date created:  2023.08.26
 * @version:       1.0.0
 * @par copyright (c):
 *   
 * @par history (desc):
 *   version:1.0.0, wjh, 2023.08.26,19:37:42
 */


#ifndef _ENCODERCALIBRATOR_H_
#define _ENCODERCALIBRATOR_H_

/* Include Files **************************************************************/
#include "Datatype.h"

/* Macro Definition ***********************************************************/
#define MAX_NUM_OF_FOURIER_SERIES 10
#define MIN_AMP 0.00001

/* Data Type Define ***********************************************************/
typedef struct FourierCoeff
{
    float A;
    float f;
    float phi;
}FourierCoeff;

typedef struct EncoderCalibrator
{
    /* public data */
    FourierCoeff coeffs[MAX_NUM_OF_FOURIER_SERIES];
    uint32_t param_en;
    uint32_t param_encoder_max_pulse;

    uint16_t num_of_item;
    float encoder2rad;
    float rad2encoder;

    /* private data */
    
    /* public method */
    void (*Init)(struct EncoderCalibrator *self);
    int32_t (*Run)(struct EncoderCalibrator *self, int32_t encoder);
    float (*FourierSeries)(struct EncoderCalibrator *self, float theta);

    /* private method */
    
}EncoderCalibrator;
    
/* Variable Declare ***********************************************************/

/* Function Declare ***********************************************************/
void EncoderCalibrator_Init(struct EncoderCalibrator *self);
int32_t EncoderCalibrator_Run(struct EncoderCalibrator *self, int32_t encoder);
float EncoderCalibrator_FourierSeries(struct EncoderCalibrator *self, float theta);


#endif